import {
  Inject,
  Controller,
  Post,
  Put,
  Del,
  Get,
  Param,
  Body,
  Queries
} from "@midwayjs/core";
import { Context } from "@midwayjs/koa";
import { Utils } from "../utils/index";
import { ClubService } from "../service/club.service";
import { ClubCreateDto, ClubPageQueryDto } from "../dto/club.dto";

@Controller()
export class ClubController {
  @Inject()
  ctx: Context;

  @Inject()
  clubService: ClubService;

  @Inject()
  utils: Utils;

  @Post("/auth-api/club", { summary: "添加球杆" })
  async add_club(@Body() dto: ClubCreateDto) {
    const result = await this.clubService.add_club(dto);
    return this.utils.response.success({
      ...result
    });
  }

  @Put("/auth-api/club/:clubId", { summary: "更新球杆" })
  async update_club(
    @Param("clubId") clubId: string,
    @Body() dto: ClubCreateDto
  ) {
    const result = await this.clubService.update_club(clubId, dto);
    return this.utils.response.success({
      ...result
    });
  }
  @Del("/auth-api/club/:clubId", { summary: "删除球杆" })
  async delete_club(@Param("clubId") clubId: string) {
    const result = await this.clubService.delete_club(clubId);
    return this.utils.response.success({
      ...result
    });
  }

  @Get("/common-api/club/list", { summary: "获取球杆列表" })
  async get_club_list() {
    const result = await this.clubService.get_club_list();
    return this.utils.response.success({
      ...result
    });
  }

  @Get("/common-api/club/page", { summary: "获取球杆分页列表" })
  async get_club_page_list(@Queries() dto: ClubPageQueryDto) {
    const result = await this.clubService.get_club_page_list(dto);
    return this.utils.response.success({
      ...result
    });
  }
}
